﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace Framework.Logic.Settings
{
    public abstract class FileSystem
    {
        public static string GetMCServerLocation(OpenFileDialog fileDialog)
        {
            string filePath = "";
            var fileType = FileType.Other;
            if (config.Default.FileLocation != null && File.Exists(config.Default.FileLocation))
            {
                filePath = config.Default.FileLocation;
                if (Path.GetExtension(filePath) == ".jar")
                {
                    fileType = FileType.Jar;
                }
                else if (Path.GetExtension(filePath) == ".bat")
                {
                    fileType = FileType.Bat;
                }
            }

            if (fileType == FileType.Other)
            {
                try
                {
                   filePath = SetMCServerLocation(fileDialog);
                }
                catch (ArgumentException)
                {
                    throw;
                }
            }
                return filePath;
        }

        public static string GetMCServerLocation()
        {
            return config.Default.FileLocation;
        }

        public static string SetMCServerLocation(OpenFileDialog fileDialog)
        {
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                config.Default.FileLocation = fileDialog.FileName;
                config.Default.Save();
                return fileDialog.FileName;
            }
            throw new ArgumentException("Cancelled out of file selection");
        }

		public static void SetMCServerLocation(string strFilePath)
		{
            config.Default.FileLocation = strFilePath;
            config.Default.Save();
		}

        public enum FileType
        {
            Other,
            Jar,
            Bat
        }
    }
}
